package mms.tooleditor;

import com.mxgraph.canvas.mxGraphics2DCanvas;
import com.mxgraph.shape.mxIMarker;
import com.mxgraph.shape.mxMarkerRegistry;
import com.mxgraph.util.mxPoint;
import com.mxgraph.view.mxCellState;

import java.awt.*;

public class ERMarkers {
    public static final String CONNECTOR_COMPOSITION = "composition";
    public static final String CONNECTOR_AGGREGATION = "aggregation";


    public static void init() {

        mxMarkerRegistry.registerMarker(CONNECTOR_COMPOSITION, new mxIMarker() {
            public mxPoint paintMarker(mxGraphics2DCanvas canvas,
                                       mxCellState state, String type, mxPoint pe, double nx,
                                       double ny, double size, boolean source) {
                Polygon poly = new Polygon();
                poly.addPoint((int) Math.round(pe.getX()),
                        (int) Math.round(pe.getY()));
                poly.addPoint((int) Math.round(pe.getX() - nx / 2 - ny / 2),
                        (int) Math.round(pe.getY() + nx / 2 - ny / 2));
                poly.addPoint((int) Math.round(pe.getX() - nx),
                        (int) Math.round(pe.getY() - ny));
                poly.addPoint((int) Math.round(pe.getX() - nx / 2 + ny / 2),
                        (int) Math.round(pe.getY() - ny / 2 - nx / 2));

                canvas.fillShape(poly);

                canvas.getGraphics().draw(poly);

                return new mxPoint(-nx / 2, -ny / 2);
            }
        });
    }

}
